/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is subject to terms and conditions of the Shared Source License
* for DSL Editor PowerToy. A copy of the license can be found in the License.htm file
* at the root of this distribution. If you can not locate the Shared Source License
* for DSL Editor PowerToy, please obtain a copy from: http://www.codeplex.com/dsltreegrideditor/Project/License.aspx.
* By using this source code in any fashion, you are agreeing to be bound by
* the terms of the Shared Source License for DSL Editor PowerToy.
*
* You must not remove this notice, or any other, from this software.
*
* **********************************************************************************/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;

using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;

namespace DslEditorPowerToy.Languages.EditorConfiguration
{
    #region Shape Appearance
     partial class DslEditorShape
    {
        #region Public Properties
        public override ShapeGeometry ShapeGeometry
        {
            get
            {
                //Return new geometry
                return new HeadStoneShapeGeometry();
            }
        }
        #endregion

        #region Protected Methods
        protected override AreaField CreateBackgroundGradientField(string fieldName)
        {
            //Return new geometry shape for gradient fill
            return new HeadStoneShapeAreaField(fieldName);
        }
        #endregion
    }
    #endregion

    #region Property Changes Appearance
    partial class DslEditorShape
    {
        public override void OnShapeInserted()
        {
            base.OnShapeInserted();

            //BUGFIX: Force update on property to fix bug in DslTools
            ShapeHelper.ForceAssociatedPropertyValueUpdate(this, "Active");
        }
        protected override void InitializeResources(StyleSet classStyleSet)
        {
            base.InitializeResources(classStyleSet);

            //Register handler for property changes
            DslEditorShape.AssociateValueWith(this.Store, DslEditor.ActiveDomainPropertyId);
        }
        /// <summary>
        /// Handles property changes
        /// </summary>
        /// <param name="e"></param>
        protected override void OnAssociatedPropertyChanged(PropertyChangedEventArgs e)
        {
            //Check which property has changed
            if ("Active".Equals(e.PropertyName)) 
            {
                //Update visual styles
                bool isActive = (bool)e.NewValue;
                UpdateShapeFadeEffect(!isActive);
            }

            base.OnAssociatedPropertyChanged(e);
        }

        #region Private Methods
        /// <summary>
        /// Updates the shapes visual appearance of the shape
        /// </summary>
        /// <param name="faded"></param>
        private void UpdateShapeFadeEffect(bool faded)
        {
            //Update outline
            DrawingHelper.UpdateOutlineStyle(this, faded, DashStyle.Dash, Color.FromKnownColor(KnownColor.ActiveCaption));

            //Update text
            DrawingHelper.UpdateShapeTextStyle(this, faded, Color.FromKnownColor(KnownColor.DimGray));

            //Update fill
            DrawingHelper.UpdateBackgroundFillColor(this, faded, Color.FromKnownColor(KnownColor.Silver));
        }
        #endregion
    }
    #endregion
}
